\hypertarget{cmd__server_8c}{}\doxysection{cmd\+\_\+server.\+c File Reference}
\label{cmd__server_8c}\index{cmd\_server.c@{cmd\_server.c}}
{\ttfamily \#include $<$stdio.\+h$>$}\newline
{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$errno.\+h$>$}\newline
{\ttfamily \#include $<$stdlib.\+h$>$}\newline
{\ttfamily \#include $<$unistd.\+h$>$}\newline
{\ttfamily \#include $<$sys/socket.\+h$>$}\newline
{\ttfamily \#include $<$sys/types.\+h$>$}\newline
{\ttfamily \#include $<$sys/stat.\+h$>$}\newline
{\ttfamily \#include $<$netinet/in.\+h$>$}\newline
{\ttfamily \#include $<$arpa/inet.\+h$>$}\newline
{\ttfamily \#include $<$dirent.\+h$>$}\newline
{\ttfamily \#include $<$time.\+h$>$}\newline
{\ttfamily \#include $<$fcntl.\+h$>$}\newline
{\ttfamily \#include \char`\"{}ftp\+\_\+server.\+h\char`\"{}}\newline
{\ttfamily \#include \char`\"{}cmd\+\_\+server.\+h\char`\"{}}\newline
{\ttfamily \#include \char`\"{}config.\+h\char`\"{}}\newline
Include dependency graph for cmd\+\_\+server.\+c\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{cmd__server_8c__incl}
\end{center}
\end{figure}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \mbox{\hyperlink{cmd__server_8c_a4885d7333efacbab7886c841527a5c3f}{set\+\_\+file\+\_\+dir}} (char $\ast$src, char $\ast$file)
\begin{DoxyCompactList}\small\item\em 拼接当前工作目录和给出的参数，得到完整路径。 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{cmd__server_8c_a68ed484e70fa77e339d9288d943ab4e6}{set\+\_\+cmd\+\_\+arg}} (\mbox{\hyperlink{structMsg}{Msg}} $\ast$msg, char $\ast$cmd\+\_\+arg, int bit)
\begin{DoxyCompactList}\small\item\em 从客户端给出的信息中提取规范化的参数，供之后的具体操作使用。 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{cmd__server_8c_a791b072f3c807a07d8f31f79234df324}{server\+\_\+list}} (int client\+\_\+sock, \mbox{\hyperlink{structMsg}{Msg}} $\ast$msg)
\begin{DoxyCompactList}\small\item\em 打印当前工作目录。 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{cmd__server_8c_a85d6867e8cd03abe695768d9b067d57d}{server\+\_\+put}} (int client\+\_\+sock, \mbox{\hyperlink{structMsg}{Msg}} $\ast$msg)
\begin{DoxyCompactList}\small\item\em 向服务端发送文件，可选择\+ASCII和\+Binary两种模式。若文件不存在，将会报错。 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{cmd__server_8c_aa50384f65cd75709e683b2c7f08581c1}{server\+\_\+get}} (int client\+\_\+sock, \mbox{\hyperlink{structMsg}{Msg}} $\ast$msg)
\begin{DoxyCompactList}\small\item\em 从服务端获取文件，可选择\+ASCII和\+Binary两种模式。若文件不存在，将会报错。 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{cmd__server_8c_a338cb5462d42666ddab20076f7bd982f}{server\+\_\+mkd}} (int client\+\_\+sock, \mbox{\hyperlink{structMsg}{Msg}} $\ast$msg)
\begin{DoxyCompactList}\small\item\em 根据客户端给出的参数，创建相应目录。若目录已存在，将会报错。 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{cmd__server_8c_a37c028d5fa7f16c48ecfb86321d4c846}{server\+\_\+rmd}} (int client\+\_\+sock, \mbox{\hyperlink{structMsg}{Msg}} $\ast$msg)
\begin{DoxyCompactList}\small\item\em 根据客户端给出的参数，删除相应目录。若目录不存在，将会报错。 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{cmd__server_8c_acde9e10e0cad1c21935492f0a6d4045d}{server\+\_\+del}} (int client\+\_\+sock, \mbox{\hyperlink{structMsg}{Msg}} $\ast$msg)
\begin{DoxyCompactList}\small\item\em 根据客户端给出的参数，删除相应文件。若文件不存在，将会报错。 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{cmd__server_8c_a64932a67c58d957e2482e0436b7c203c}{server\+\_\+cwd}} (int client\+\_\+sock, \mbox{\hyperlink{structMsg}{Msg}} $\ast$msg)
\begin{DoxyCompactList}\small\item\em 根据客户端给出的参数，改变当前工作目录。 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{cmd__server_8c_a3430c69a06c184495cd28c57f4fe0f7e}{server\+\_\+pwd}} (int client\+\_\+sock, \mbox{\hyperlink{structMsg}{Msg}} $\ast$msg)
\begin{DoxyCompactList}\small\item\em 向客户端发送目前所在的工作目录。 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{cmd__server_8c_a9020d28c81a4a7ab08d2acfb369844c7}{handle\+\_\+port}} (int client\+\_\+sock, \mbox{\hyperlink{structMsg}{Msg}} $\ast$msg)
\begin{DoxyCompactList}\small\item\em 处理\+PORT连接的请求。扫描客户端发送的地址信息并连接，生成传递数据的套接字。 \end{DoxyCompactList}\item 
struct sockaddr\+\_\+in \mbox{\hyperlink{cmd__server_8c_a122d023237866867fcdf8ee05bf2c25c}{create\+\_\+data\+\_\+sock}} (int $\ast$sock)
\begin{DoxyCompactList}\small\item\em 在创建\+PASV连接时使用，生成传递数据所需要的套接字并完成绑定和监听。 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{cmd__server_8c_ac7ed6e7fa09e32bb518a19a70f5f5565}{handle\+\_\+pasv}} (int client\+\_\+sock, \mbox{\hyperlink{structMsg}{Msg}} $\ast$msg)
\begin{DoxyCompactList}\small\item\em 处理\+PASV连接的请求。连接成功后，将向客户端发送相应的地址信息，并生成传递数据的套接字。 \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Implementation of the commands in the ftp server.

\begin{DoxyAuthor}{Author}
wgy, sc 
\end{DoxyAuthor}
\begin{DoxyVersion}{Version}
V1.\+0 
\end{DoxyVersion}
\begin{DoxyDate}{Date}
2022-\/11-\/19 
\end{DoxyDate}
\begin{DoxyCopyright}{Copyright}
GNU Public License V3.\+0 
\end{DoxyCopyright}


\doxysubsection{Function Documentation}
\mbox{\Hypertarget{cmd__server_8c_a122d023237866867fcdf8ee05bf2c25c}\label{cmd__server_8c_a122d023237866867fcdf8ee05bf2c25c}} 
\index{cmd\_server.c@{cmd\_server.c}!create\_data\_sock@{create\_data\_sock}}
\index{create\_data\_sock@{create\_data\_sock}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{create\_data\_sock()}{create\_data\_sock()}}
{\footnotesize\ttfamily struct sockaddr\+\_\+in create\+\_\+data\+\_\+sock (\begin{DoxyParamCaption}\item[{int $\ast$}]{sock }\end{DoxyParamCaption})}



在创建\+PASV连接时使用，生成传递数据所需要的套接字并完成绑定和监听。 


\begin{DoxyParams}{Parameters}
{\em sock} & 将要更改的套接字变量的指针。无需初始化。 \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
配置好的用户sockaddr\+\_\+in信息。 
\end{DoxyReturn}
\mbox{\Hypertarget{cmd__server_8c_ac7ed6e7fa09e32bb518a19a70f5f5565}\label{cmd__server_8c_ac7ed6e7fa09e32bb518a19a70f5f5565}} 
\index{cmd\_server.c@{cmd\_server.c}!handle\_pasv@{handle\_pasv}}
\index{handle\_pasv@{handle\_pasv}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{handle\_pasv()}{handle\_pasv()}}
{\footnotesize\ttfamily void handle\+\_\+pasv (\begin{DoxyParamCaption}\item[{int}]{client\+\_\+sock,  }\item[{\mbox{\hyperlink{structMsg}{Msg}} $\ast$}]{msg }\end{DoxyParamCaption})}



处理\+PASV连接的请求。连接成功后，将向客户端发送相应的地址信息，并生成传递数据的套接字。 


\begin{DoxyParams}{Parameters}
{\em client\+\_\+sock} & 连接客户端的套接字描述符。 \\
\hline
{\em msg} & 服务端配置参数的指针。 \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{cmd__server_8c_a9020d28c81a4a7ab08d2acfb369844c7}\label{cmd__server_8c_a9020d28c81a4a7ab08d2acfb369844c7}} 
\index{cmd\_server.c@{cmd\_server.c}!handle\_port@{handle\_port}}
\index{handle\_port@{handle\_port}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{handle\_port()}{handle\_port()}}
{\footnotesize\ttfamily void handle\+\_\+port (\begin{DoxyParamCaption}\item[{int}]{client\+\_\+sock,  }\item[{\mbox{\hyperlink{structMsg}{Msg}} $\ast$}]{msg }\end{DoxyParamCaption})}



处理\+PORT连接的请求。扫描客户端发送的地址信息并连接，生成传递数据的套接字。 


\begin{DoxyParams}{Parameters}
{\em client\+\_\+sock} & 连接客户端的套接字描述符。 \\
\hline
{\em msg} & 服务端配置参数的指针。 \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{cmd__server_8c_a64932a67c58d957e2482e0436b7c203c}\label{cmd__server_8c_a64932a67c58d957e2482e0436b7c203c}} 
\index{cmd\_server.c@{cmd\_server.c}!server\_cwd@{server\_cwd}}
\index{server\_cwd@{server\_cwd}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{server\_cwd()}{server\_cwd()}}
{\footnotesize\ttfamily void server\+\_\+cwd (\begin{DoxyParamCaption}\item[{int}]{client\+\_\+sock,  }\item[{\mbox{\hyperlink{structMsg}{Msg}} $\ast$}]{msg }\end{DoxyParamCaption})}



根据客户端给出的参数，改变当前工作目录。 


\begin{DoxyParams}{Parameters}
{\em client\+\_\+sock} & 连接客户端的套接字描述符。 \\
\hline
{\em msg} & 服务端配置参数的指针。 \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{cmd__server_8c_acde9e10e0cad1c21935492f0a6d4045d}\label{cmd__server_8c_acde9e10e0cad1c21935492f0a6d4045d}} 
\index{cmd\_server.c@{cmd\_server.c}!server\_del@{server\_del}}
\index{server\_del@{server\_del}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{server\_del()}{server\_del()}}
{\footnotesize\ttfamily void server\+\_\+del (\begin{DoxyParamCaption}\item[{int}]{client\+\_\+sock,  }\item[{\mbox{\hyperlink{structMsg}{Msg}} $\ast$}]{msg }\end{DoxyParamCaption})}



根据客户端给出的参数，删除相应文件。若文件不存在，将会报错。 


\begin{DoxyParams}{Parameters}
{\em client\+\_\+sock} & 连接客户端的套接字描述符。 \\
\hline
{\em msg} & 服务端配置参数的指针。 \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{cmd__server_8c_aa50384f65cd75709e683b2c7f08581c1}\label{cmd__server_8c_aa50384f65cd75709e683b2c7f08581c1}} 
\index{cmd\_server.c@{cmd\_server.c}!server\_get@{server\_get}}
\index{server\_get@{server\_get}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{server\_get()}{server\_get()}}
{\footnotesize\ttfamily void server\+\_\+get (\begin{DoxyParamCaption}\item[{int}]{client\+\_\+sock,  }\item[{\mbox{\hyperlink{structMsg}{Msg}} $\ast$}]{msg }\end{DoxyParamCaption})}



从服务端获取文件，可选择\+ASCII和\+Binary两种模式。若文件不存在，将会报错。 


\begin{DoxyParams}{Parameters}
{\em client\+\_\+sock} & 连接客户端的套接字描述符。 \\
\hline
{\em msg} & 服务端配置参数的指针。 \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{cmd__server_8c_a791b072f3c807a07d8f31f79234df324}\label{cmd__server_8c_a791b072f3c807a07d8f31f79234df324}} 
\index{cmd\_server.c@{cmd\_server.c}!server\_list@{server\_list}}
\index{server\_list@{server\_list}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{server\_list()}{server\_list()}}
{\footnotesize\ttfamily void server\+\_\+list (\begin{DoxyParamCaption}\item[{int}]{client\+\_\+sock,  }\item[{\mbox{\hyperlink{structMsg}{Msg}} $\ast$}]{msg }\end{DoxyParamCaption})}



打印当前工作目录。 


\begin{DoxyParams}{Parameters}
{\em client\+\_\+sock} & 连接客户端的套接字描述符。 \\
\hline
{\em msg} & 服务端配置参数的指针。 \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{cmd__server_8c_a338cb5462d42666ddab20076f7bd982f}\label{cmd__server_8c_a338cb5462d42666ddab20076f7bd982f}} 
\index{cmd\_server.c@{cmd\_server.c}!server\_mkd@{server\_mkd}}
\index{server\_mkd@{server\_mkd}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{server\_mkd()}{server\_mkd()}}
{\footnotesize\ttfamily void server\+\_\+mkd (\begin{DoxyParamCaption}\item[{int}]{client\+\_\+sock,  }\item[{\mbox{\hyperlink{structMsg}{Msg}} $\ast$}]{msg }\end{DoxyParamCaption})}



根据客户端给出的参数，创建相应目录。若目录已存在，将会报错。 


\begin{DoxyParams}{Parameters}
{\em client\+\_\+sock} & 连接客户端的套接字描述符。 \\
\hline
{\em msg} & 服务端配置参数的指针。 \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{cmd__server_8c_a85d6867e8cd03abe695768d9b067d57d}\label{cmd__server_8c_a85d6867e8cd03abe695768d9b067d57d}} 
\index{cmd\_server.c@{cmd\_server.c}!server\_put@{server\_put}}
\index{server\_put@{server\_put}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{server\_put()}{server\_put()}}
{\footnotesize\ttfamily void server\+\_\+put (\begin{DoxyParamCaption}\item[{int}]{client\+\_\+sock,  }\item[{\mbox{\hyperlink{structMsg}{Msg}} $\ast$}]{msg }\end{DoxyParamCaption})}



向服务端发送文件，可选择\+ASCII和\+Binary两种模式。若文件不存在，将会报错。 


\begin{DoxyParams}{Parameters}
{\em client\+\_\+sock} & 连接客户端的套接字描述符。 \\
\hline
{\em msg} & 服务端配置参数的指针。 \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{cmd__server_8c_a3430c69a06c184495cd28c57f4fe0f7e}\label{cmd__server_8c_a3430c69a06c184495cd28c57f4fe0f7e}} 
\index{cmd\_server.c@{cmd\_server.c}!server\_pwd@{server\_pwd}}
\index{server\_pwd@{server\_pwd}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{server\_pwd()}{server\_pwd()}}
{\footnotesize\ttfamily void server\+\_\+pwd (\begin{DoxyParamCaption}\item[{int}]{client\+\_\+sock,  }\item[{\mbox{\hyperlink{structMsg}{Msg}} $\ast$}]{msg }\end{DoxyParamCaption})}



向客户端发送目前所在的工作目录。 


\begin{DoxyParams}{Parameters}
{\em client\+\_\+sock} & 连接客户端的套接字描述符。 \\
\hline
{\em msg} & 服务端配置参数的指针。 \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{cmd__server_8c_a37c028d5fa7f16c48ecfb86321d4c846}\label{cmd__server_8c_a37c028d5fa7f16c48ecfb86321d4c846}} 
\index{cmd\_server.c@{cmd\_server.c}!server\_rmd@{server\_rmd}}
\index{server\_rmd@{server\_rmd}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{server\_rmd()}{server\_rmd()}}
{\footnotesize\ttfamily void server\+\_\+rmd (\begin{DoxyParamCaption}\item[{int}]{client\+\_\+sock,  }\item[{\mbox{\hyperlink{structMsg}{Msg}} $\ast$}]{msg }\end{DoxyParamCaption})}



根据客户端给出的参数，删除相应目录。若目录不存在，将会报错。 


\begin{DoxyParams}{Parameters}
{\em client\+\_\+sock} & 连接客户端的套接字描述符。 \\
\hline
{\em msg} & 服务端配置参数的指针。 \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{cmd__server_8c_a68ed484e70fa77e339d9288d943ab4e6}\label{cmd__server_8c_a68ed484e70fa77e339d9288d943ab4e6}} 
\index{cmd\_server.c@{cmd\_server.c}!set\_cmd\_arg@{set\_cmd\_arg}}
\index{set\_cmd\_arg@{set\_cmd\_arg}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{set\_cmd\_arg()}{set\_cmd\_arg()}}
{\footnotesize\ttfamily void set\+\_\+cmd\+\_\+arg (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structMsg}{Msg}} $\ast$}]{msg,  }\item[{char $\ast$}]{cmd\+\_\+arg,  }\item[{int}]{bit }\end{DoxyParamCaption})}



从客户端给出的信息中提取规范化的参数，供之后的具体操作使用。 


\begin{DoxyParams}{Parameters}
{\em msg} & 服务端配置参数的指针，此处使用接收到的客户端消息数据。 \\
\hline
{\em cmd\+\_\+arg} & 存放规范化参数的位置。 \\
\hline
{\em bit} & 命令的位数。参数将会从命令之后开始读取。 \\
\hline
\end{DoxyParams}
\mbox{\Hypertarget{cmd__server_8c_a4885d7333efacbab7886c841527a5c3f}\label{cmd__server_8c_a4885d7333efacbab7886c841527a5c3f}} 
\index{cmd\_server.c@{cmd\_server.c}!set\_file\_dir@{set\_file\_dir}}
\index{set\_file\_dir@{set\_file\_dir}!cmd\_server.c@{cmd\_server.c}}
\doxysubsubsection{\texorpdfstring{set\_file\_dir()}{set\_file\_dir()}}
{\footnotesize\ttfamily void set\+\_\+file\+\_\+dir (\begin{DoxyParamCaption}\item[{char $\ast$}]{src,  }\item[{char $\ast$}]{file }\end{DoxyParamCaption})}



拼接当前工作目录和给出的参数，得到完整路径。 


\begin{DoxyParams}{Parameters}
{\em src} & 将要存放得到的路径字符串的位置。 \\
\hline
{\em file} & 具体文件名的字符串指针。 \\
\hline
\end{DoxyParams}
